{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Question 16\n",
    "\n",
    "### **Question:**\n",
    "\n",
    "> **_Use a list comprehension to square each odd number in a list. The list is input by a sequence of comma-separated numbers._** >**_Suppose the following input is supplied to the program:_**\n",
    "\n",
    "\n",
    "1,2,3,4,5,6,7,8,9\n",
    "\n",
    "\n",
    "> **_Then, the output should be:_**\n",
    "\n",
    "\n",
    "1,9,25,49,81\n",
    "\n",
    "\n",
    "---\n",
    "\n",
    "### Hints:\n",
    "\n",
    "> **_In case of input data being supplied to the question, it should be assumed to be a console input._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "lst = [str(int(i) ** 2) for i in input().split(\",\") if int(i) % 2]\n",
    "print(\",\".join(lst))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"Solution by: shagun\"\"\"\n",
    "\n",
    "lst = input().split(\",\")  # splits in comma position and set up in list\n",
    "\n",
    "seq = []\n",
    "lst = [int(i) for i in lst]  # converts string to integer\n",
    "for i in lst:\n",
    "    if i % 2 != 0:\n",
    "        i = i * i\n",
    "        seq.append(i)\n",
    "\n",
    "\n",
    "seq = [\n",
    "    str(i) for i in seq\n",
    "]  # All the integers are converted to string to be able to apply join operation\n",
    "print(\",\".join(seq))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "**_There were a mistake in the the test case and the solution's whice were notified and fixed with the help of @dwedigital. My warm thanks to him._**\n",
    "\n",
    "# Question 17\n",
    "\n",
    "### **Question:**\n",
    "\n",
    "> **_Write a program that computes the net amount of a bank account based a transaction log from console input. The transaction log format is shown as following:_**\n",
    "\n",
    "```\n",
    "D 100\n",
    "W 200\n",
    "```\n",
    "\n",
    "- D means deposit while W means withdrawal.\n",
    "\n",
    "> **_Suppose the following input is supplied to the program:_**\n",
    "\n",
    "```\n",
    "D 300\n",
    "D 300\n",
    "W 200\n",
    "D 100\n",
    "```\n",
    "\n",
    "> **_Then, the output should be:_**\n",
    "\n",
    "```\n",
    "500\n",
    "```\n",
    "\n",
    "---\n",
    "\n",
    "### Hints:\n",
    "\n",
    "> **_In case of input data being supplied to the question, it should be assumed to be a console input._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "total = 0\n",
    "while True:\n",
    "    s = input().split()\n",
    "    if not s:  # break if the string is empty\n",
    "        break\n",
    "    cm, num = map(\n",
    "        str, s\n",
    "    )  # two inputs are distributed in cm and num in string data type\n",
    "\n",
    "    if cm == \"D\":\n",
    "        total += int(num)\n",
    "    if cm == \"W\":\n",
    "        total -= int(num)\n",
    "\n",
    "print(total)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"Solution by: leonedott\"\"\"\n",
    "\n",
    "lst = []\n",
    "while True:\n",
    "    x = input()\n",
    "    if len(x) == 0:\n",
    "        break\n",
    "    lst.append(x)\n",
    "\n",
    "balance = 0\n",
    "for item in lst:\n",
    "    if \"D\" in item:\n",
    "        balance += int(item.strip(\"D \"))\n",
    "    if \"W\" in item:\n",
    "        balance -= int(item.strip(\"W \"))\n",
    "print(balance)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"Solution by: AlexanderSro\"\"\"\n",
    "\n",
    "account = 0\n",
    "while True:\n",
    "    action = input(\"Deposit/Whitdrow/Balance/Quit? D/W/B/Q: \").lower()\n",
    "    if action == \"d\":\n",
    "        deposit = input(\"How much would you like to deposit? \")\n",
    "        account = account + int(deposit)\n",
    "    elif action == \"w\":\n",
    "        withdrow = input(\"How much would you like to withdrow? \")\n",
    "        account = account - int(withdrow)\n",
    "    elif action == \"b\":\n",
    "        print(account)\n",
    "    else:\n",
    "        quit()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"Solution by: ShalomPrinz\n",
    "\"\"\"\n",
    "lines = []\n",
    "while True:\n",
    "    loopInput = input()\n",
    "    if loopInput == \"done\":\n",
    "        break\n",
    "    else:\n",
    "        lines.append(loopInput)\n",
    "\n",
    "lst = list(int(i[2:]) if i[0] == \"D\" else -int(i[2:]) for i in lines)\n",
    "print(sum(lst))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
